import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
    //声明数据 state
    const count = ref(100)
    const msg = ref('hello pinia')
    const user=ref({name:'zhangsan',age:18})
    const img  = require("@/assets/logo.png")
    const url= "https://www.baidu.com"
    //声明操作数据的方法 action(普通函数就可以)
    const addCount = () => {
        count.value++
    }
    const subCount = () => {
        count.value--
    }
    //声明基于数据派生的计算属性getters(computed)
    const doubleCount = computed(() => count.value * 2)

    return { count, msg,addCount,subCount,doubleCount,user ,img,url}
},{
    persist:true   //开启当前模块的持久化
})